﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

namespace WINBASE
{
    public static class ApplicationData
    {
        static internal DataTable dtMenu;
        static internal DataTable dtNodes;
        static internal DataTable dtAppSetting;
        public static int LoginTrxNo;

        public static Font AppFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

        public static void InitializeData()
        {
            dtMenu = ApplicationService.QueryHelper.GetAView("fmmd1", "ISNULL([VisibleFlag],'Y') = 'Y'", "Sort");

            //int UserRoleTrxNo = (int)QueryHelper.GetAVal("SELECT TrxNo FROM rcur1 WHERE UserRoleCode = (SELECT TOP 1 UserRoleCode FROM rcus1 WHERE UserId = @s)", WLCGlobalData.LoginUserId);
            //dtNodes = QueryHelper.GetADataTable("SELECT f1.* FROM fmnd1 f1 " +
            //                                        "INNER JOIN rcur2 r2 ON r2.ModuleTrxNo = f1.[ModuleTrxNo] AND " +
            //                                                                "ISNULL(r2.ParentTrxNo,0) = ISNULL(f1.[ParentTrxNo],0) AND " +
            //                                                                "r2.NodeTrxNo = f1.[TrxNo] " +
            //                                    "WHERE ISNULL([VisibleFlag],'Y') = 'Y' AND r2.OpenFlag = 'Y' AND r2.TrxNo = @s", UserRoleTrxNo);

            dtNodes = ApplicationService.QueryHelper.GetADataTable("SELECT f1.* FROM fmnd1 f1 WHERE ISNULL([VisibleFlag],'Y') = 'Y'");
            //dtAppSetting = QueryHelper.GetADataTable("SELECT TOP 1 * FROM saap1");
        }

        //public static void InitializeData()
        //{
        //    dtMenu = ApplicationService.QueryHelper.GetAView("vw_fmmd1", "ISNULL([Visible Flag],'Y') = 'Y'", "Sort");

        //    int UserRoleTrxNo = (int)ApplicationService.QueryHelper.GetAVal("SELECT TrxNo FROM rcur1 WHERE UserRoleCode = (SELECT TOP 1 UserRoleCode FROM rcus1 WHERE UserId = @s)", ApplicationData.UserId);
        //    dtNodes = ApplicationService.QueryHelper.GetADataTable("SELECT f1.* FROM vw_fmnd1 f1 " +
        //                                            "INNER JOIN rcur2 r2 ON r2.ModuleTrxNo = f1.[Module Trx No] AND " +
        //                                                                    "ISNULL(r2.ParentTrxNo,0) = ISNULL(f1.[Parent Trx No],0) AND " +
        //                                                                    "r2.NodeTrxNo = f1.[Trx No] " +
        //                                        "WHERE ISNULL([Visible Flag],'Y') = 'Y' AND r2.OpenFlag = 'Y' AND r2.TrxNo = @s", UserRoleTrxNo);
        //    dtAppSetting = ApplicationService.QueryHelper.GetADataTable("SELECT TOP 1 * FROM saap1");
        //}

        public static DataTable DtModule
        {
            get { return ApplicationData.dtMenu; }
            set { ApplicationData.dtMenu = value; }
        }

        public static DataTable DtNodes
        {
            get { return ApplicationData.dtNodes; }
            set { ApplicationData.dtNodes = value; }
        }

        public static DataTable DtAppSetting
        {
            get { return ApplicationData.dtAppSetting; }
        }

        public static string WorkStation
        {
            get { return System.Net.Dns.GetHostName(); }
        }

        static string userId = "S";
        public static string UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        static string userName = "System Admin";
        public static string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
    }
}